import { SimpleChange } from '@angular/core';

const fnMergeProperty = (source: any, target: any): void => {
  for (const key in target) {
    if (source.hasOwnProperty(key)) {
      source = target[key];
    }
  }
};

/**
 * 转化成RMB元字符串
 *
 * @param digits 当数字类型时，允许指定小数点后数字的个数，默认2位小数
 */
const fnYuan = (value: number | string, digits: number = 2): string => {
  if (typeof value === 'number') {
    value = value.toFixed(digits);
  }
  return `&yen ${value}`;
};

const fnIsOnChanged = (prop: SimpleChange, callback: (value: any) => void): void => {
  if (prop !== undefined && prop.currentValue !== undefined) {
    callback(prop.currentValue);
  }
};

export { fnMergeProperty, fnYuan, fnIsOnChanged };
